"use strict";
cc._RF.push(module, '34fc4sehVRGmbtHO8V5Zk5T', 'Player');
// Script/Player.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var AppDef_1 = require("./Core/AppDef");
var AppEvent_1 = require("./Core/AppEvent");
var EventManager_1 = require("./Managers/EventManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Player = /** @class */ (function (_super) {
    __extends(Player, _super);
    function Player() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.anim = null;
        _this.weapon = null;
        _this.hpNode = null;
        _this.playerType = AppDef_1.PLAYER_TYPE.My;
        _this.weaponType = AppDef_1.WEAPON_TYPE.My;
        _this.p = cc.v3(0, 0, 0);
        _this.weaponP = cc.v3(0, 0, 0);
        _this.weaponAngle = 0;
        _this.attackCooling = 0;
        _this.attackCoolingTime = 0.2;
        _this.nick = "a";
        _this.hp = 100;
        return _this;
    }
    Player.prototype.onLoad = function () {
        var _this = this;
        this.schedule(function () {
            _this.onMove();
        }, 0.01);
    };
    Player.prototype.init = function (playerType, weaponType, nick) {
        if (playerType) {
            this.playerType = playerType;
        }
        if (weaponType) {
            this.weaponType = weaponType;
        }
        if (nick) {
            this.nick = nick;
        }
        this.hp = 100;
        this.p = cc.v3(0, 0, 0);
        this.weaponP = cc.v3(0, 0, 0);
        this.weaponAngle = 0;
    };
    Player.prototype.setHpReduce = function (hit) {
        this.hpNode.scaleX = (this.hp - hit) / 100;
        this.hp -= hit;
    };
    Player.prototype.getPlayerHp = function () {
        return this.hp;
    };
    Player.prototype.start = function () {
        this.changeAnim("idle");
    };
    Player.prototype.setP = function (p) {
        this.p = p.multiplyScalar(5);
    };
    Player.prototype.setWeaponP = function (data) {
        this.weaponP = data.p.multiplyScalar(5);
        if (data.angle) {
            this.weaponAngle = data.angle;
            this.weapon.angle = this.weaponAngle;
        }
        if (data.scalex) {
            this.node.scaleX = data.scalex;
        }
    };
    Player.prototype.onMove = function () {
        this.node.position = this.node.position.add(this.p);
        if (this.p.mag() !== 0) {
            this.changeAnim("run");
        }
        else {
            this.changeAnim("idle");
        }
        if (this.attackCooling > 0) {
            this.attackCooling -= 0.01;
        }
        if (this.weaponP.mag() !== 0 && this.attackCooling <= 0) {
            this.weapon.getComponent(cc.Animation).play("weaponAttack");
            this.attackCooling = this.attackCoolingTime;
            var pos = this.weapon.convertToWorldSpaceAR(new cc.Vec3(0, 0));
            EventManager_1.dispatchEvent(AppEvent_1.EVT_CREATE_BULLET, { weaponType: this.weaponType, pos: pos, weaponP: this.weaponP, from: this.nick });
        }
    };
    Player.prototype.changeAnim = function (name) {
        if (this.anim.currentClip === null || this.anim.currentClip.name !== name) {
            this.anim.play(name);
        }
    };
    __decorate([
        property(cc.Animation)
    ], Player.prototype, "anim", void 0);
    __decorate([
        property(cc.Node)
    ], Player.prototype, "weapon", void 0);
    __decorate([
        property(cc.Node)
    ], Player.prototype, "hpNode", void 0);
    Player = __decorate([
        ccclass
    ], Player);
    return Player;
}(cc.Component));
exports.default = Player;

cc._RF.pop();